/// <reference path="jquery-1.8.2.min.js" />

var selectNode = null;

$(function () {
     $(".tree").find(".treeitem").find(".tree-node.treenode1").click(function () {
       
        //current select node 
        if (selectNode != null)
        {
           selectNode.find(".tree-hit").removeClass("tree-expanded").addClass("tree-collapsed").closest("li").animate({ height: "28px" });
           selectNode = $(this);
        }
        //
        
        if ($(this).closest(".treeitem").height() >= 32) {
            $(this).find(".tree-hit").removeClass("tree-expanded").addClass("tree-collapsed").closest("li").animate({ height: "28px" });
        }
        else {
            $(this).find(".tree-hit").removeClass("tree-collapsed").addClass("tree-expanded").closest("li").animate({ height: $(this).siblings(".treechildrenlist").height() + 28 });
        }
        return false;
    }).first().find(".tree-hit").removeClass("tree-collapsed").addClass("tree-expanded");
    
    //keep the currentNode
    selectNode = $(".tree").find(".treeitem").first();
    //
    
    $(".tree").find(".treeitem").not(":first").animate({ height: "28px" });
    
    $(".tree").find(".tree-node").hover(function () {
        if ($(this).hasClass("treenode1")) {
            $(this).addClass("tree-node-hover");
        }
        else {
            $(this).addClass("tree-content-node-hover");
        }
    }, function () {
        if ($(this).hasClass("treenode1")) {
            $(this).removeClass("tree-node-hover");
        }
        else {
            $(this).removeClass("tree-content-node-hover");
        }
    }).click(function () {
        if (!$(this).hasClass("treenode1")) { /*不包含一级栏目*/
            if (!$(this).hasClass("tree-node-selected")) {
                $(".tree").find(".tree-node").removeClass("tree-node-selected");
                $(this).addClass("tree-node-selected");
            }
        }
    });
    
    $(".tree").find(".urla").closest(".tree-node").click(function () {
        var surl = $(this).find(".urla").attr("thisurl");
        if (surl && window.parent.parent && window.parent.parent != null && window.parent.parent != undefined) {
            $(window.parent.parent.frames["workframeset"].children["workss"]).attr("src", surl);
        }
    });
    //tree-hit tree-collapsed
    $(window).resize(windowresize);
    windowresize();
});

function windowresize() {
    var wh = $(window).height();
    var ww = $(window).width();
    var lh = $("#menubanner").outerHeight(true);
    $("#treepanel").height(wh - lh);
}

function onclickMenu(url) {
    this.parent.onclickMenu(url);
}

function updatetree() {
    $('#tt').tree('collapseAll').delay(800).tree('expandAll');
}